<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="学生姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stuName">
              <j-popup
                v-model="model.stuName"
                field="stuName"
                org-fields="stu_id,stu_name"
                dest-fields="stuId,stuName"
                code="stu_info"
                :multi="true"
                @input="popupCallback"
                />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="学生编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stuId">
              <a-input v-model="model.stuId" placeholder="请输入学生编号" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="就业城市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employmenAddress">
             <j-area-linkage type="cascader" v-model="model.employmenAddress" placeholder="请输入省市区"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="入职公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employmenEnterprise">
              <a-input v-model="model.employmenEnterprise" placeholder="请输入入职公司"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="职位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employmenPosition">
              <a-input v-model="model.employmenPosition" placeholder="请输入职位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="offer" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="offer">
              <j-upload v-model="model.offer"   ></j-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试用期工资" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="probationSalary">
              <a-input-number v-model="model.probationSalary" placeholder="请输入试用期工资" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="薪资" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employmenSalary">
              <a-input-number v-model="model.employmenSalary" placeholder="请输入薪资" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="待遇" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employmenTreatment">
              <a-input v-model="model.employmenTreatment" placeholder="请输入待遇"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="入职时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employmenTime">
              <j-date placeholder="请选择入职时间"  v-model="model.employmenTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="入职结果" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employmenResult">
              <j-dict-select-tag type="list" v-model="model.employmenResult" dictCode="employmen_result" placeholder="请选择入职结果" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="失败原因" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="failureCause">
              <a-textarea v-model="model.failureCause" rows="4" placeholder="请输入失败原因" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'EmploymenInformationForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
            probationSalary:0.00,
            employmenSalary:0.00,
            employmenTreatment:"五险一金",
            failureCause:"无",
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           stuName: [
              { required: true, message: '请输入学生姓名!'},
           ],
           stuId: [
              { required: true, message: '请输入学生编号!'},
           ],
        },
        url: {
          add: "/employmen/employmenInformation/add",
          edit: "/employmen/employmenInformation/edit",
          queryById: "/employmen/employmenInformation/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      popupCallback(value,row){
         this.model = Object.assign(this.model, row);
      },
    }
  }
</script>